package cn.com.hp.feature.service.impl;

import cn.com.hp.feature.domain.dto.MenuInfoDTO;
import cn.com.hp.feature.domain.entity.MenuInfo;
import cn.com.hp.feature.domain.vo.MenuInfoVO;
import cn.com.hp.feature.domain.vo.PageVO;
import cn.com.hp.feature.mapper.MenuInfoMapper;
import cn.com.hp.feature.service.IMenuInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: hjz
 * @since: 2022/8/29
 * @description:
 */
@Service
public class MenuInfoServiceImpl  extends ServiceImpl<MenuInfoMapper, MenuInfo> implements IMenuInfoService {
    @Autowired
    private MenuInfoMapper menuInfoMapper;

    @Override
    public List<MenuInfoVO> selectList(MenuInfo menuInfo) {
        return menuInfoMapper.selectMenuList(menuInfo);
    }

    @Override
    public PageVO<MenuInfo> selectMenuPage(MenuInfoDTO menuInfoDTO) {
        PageVO<MenuInfo> data = new PageVO();

        //默认分页数据是第一页，每页10条
        int current = menuInfoDTO.getPage() == null ? 1 : menuInfoDTO.getPage();
        int size = menuInfoDTO.getRow() == null ? 10 : menuInfoDTO.getRow();
        Page<MenuInfo> page = new Page<>(current, size);
        //获取分页数据
        Page<MenuInfo> pages = menuInfoMapper.selectMenuPageByRequest(page, menuInfoDTO);
        data.setList(pages.getRecords());
        data.setPage(pages.getCurrent());
        data.setPageSize(pages.getSize());
        data.setTotal(pages.getTotal());
        return data;
    }
}
